import pymysql
import time
import os
import _thread
coon = pymysql.connect(host='127.0.0.1', user='root',
                       passwd='fan0314@', port=3306, db='fly_info', charset='utf8')
cur = coon.cursor()  # 建立游标


# 执行sql
class DBUtil():

    def exceptSql(self,sql):
        try:
            cur.execute(sql)
            res = cur.fetchall()
            return res
        except:
            return {}

    def executeSql(self,sql,data):
        #sql = "INSERT INTO userinfo(username,passwd) VALUES(%s,%s)"
        #cur.execute(sql, ("bob", "123"))
        # try:
        cur.execute(sql, data)
        coon.commit()
        # except:
        #     print("1")

    def executeMany(self,sql,data):
        try:
            cur.executemany(sql, data)
            coon.commit()
        except:
            print("1")



if __name__ == '__main__':
    #sql = 'SELECT * from message;'
    sql = 'INSERT INTO message(msg,time,level,sensitiveType) VALUES(%s,%s,%s,%s)'
    data=('你好','2020-09-09','1','政治敏感类')
    data=DBUtil().executeSql(sql,data)
    print(data)

